/*********************************************************************************
 *      Copyright:  (C) 2015 songyong<handy_skyoutlook.com>
 *                  All rights reserved.
 *
 *       Filename:  analysegps.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(2015年08月10日)
 *         Author:  sky <handy_sky@outlook.com>
 *      ChangeLog:  1, Release initial version on "2015年08月10日 19时30分46秒"
 *                 
 ********************************************************************************/
#define GBUF 512
/********************************************************************************
 *  Description:
 *   Input Args:
 *  Output Args:
 * Return Value:
 ********************************************************************************/
#if 0
struct gps
{
    char            *utc_time;
    char            gps_status;
    float           gps_lng;//经度
    float           gps_lat;
    char            lng_hemisphere;//经度半球
    char            lat_hemisphere;
    float           gps_rate;
    char            *ctc_time;
    char            gps_mode;
};
/* Time */
struct time
{
    int year;
    int month;
    int day;
    int hour;
    int minute;
    int second;
};
#endif
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

#include "gps.h"

#define Hundred 100
int analyse(char *buf,struct gps *gs,struct Gtime *tm)
{
    char *str = NULL;

    if(NULL != (str = strstr(buf,"$GPRMC")))
    {
       sscanf(str,"%*[^,],%6[0-9].000,%[^,],%f,%c,%f,%c,%f,%*[^,],%[^,],,,%c*",\
               gs->utc_time,&(gs->gps_status),&(gs->gps_lat),\
               &(gs->lat_hemisphere),&(gs->gps_lng),&(gs->lng_hemisphere),\
               &(gs->gps_rate),gs->ctc_time,&(gs->gps_mode)); 
       sscanf(gs->utc_time,"%2d%2d%2d",&(tm->hour),&(tm->minute),&(tm->second));
       sscanf(gs->ctc_time,"%2d%2d%2d",&(tm->day),&(tm->month),&(tm->year));
       tm->hour += 8;
    }
    return 0;
} /* ----- End of analyse ----- */

void print(struct gps *gp,struct Gtime *ti)
{
    printf("====================================================================================\n");
    printf("============================== GPS 全球定位导航模块 ================================\n");
    printf("==                                                                                ==\n");
    printf("==                        Author  作者：宋涌                                      ==\n");
    printf("==                        Version 版本：1.0.0                                     ==\n");
    printf("==                        Email   邮箱：<handy_sky@outlook.com>                   ==\n");
    printf("==                                                                                ==\n");
    printf("====================================================================================\n");
    printf("====================================================================================\n");
    printf("==           GPS状态位 ：%c      [A:有效状态 V：无效状态]                          ==\n",gp->gps_status);
    printf("==           GPS模式位 ：%c      [A=自主定位 D=差分 E=估算 N=数据无效]             ==\n",gp->gps_mode);
    printf("==                日期 ：%d年%d月%d日                                              ==\n",ti->year,ti->month,ti->day);
    printf("==                时间 ：%d:%d:%d                                                 ==\n",ti->hour,ti->minute,ti->second);
    switch(gp->lat_hemisphere)
    {
    case 'N':
    printf("==                纬度 ：北纬 %.3f                                              ==\n",gp->gps_lat/Hundred);
    break;
    case 'S':
    printf("==                纬度 ：南纬 %.3f                                              ==\n",gp->gps_lat/Hundred);
    break;
    }
    switch(gp->lng_hemisphere)
    {
    case 'E':
    printf("==                经度 ：东经 %.3f                                             ==\n",gp->gps_lng/Hundred);
    break;
    case 'W':
    printf("==                经度 ：西经 %.3f                                              ==\n",gp->gps_lng/Hundred);
    break;
    }
    printf("==            地面速率 ：%f                                                 ==\n",gp->gps_rate);
    printf("====================================================================================\n");
}






